package com.aibaixun.system.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.aibaixun.common.core.domain.R;
import com.aibaixun.system.domain.LkCentralfaultOrderView;
import com.aibaixun.system.domain.dto.IndexStatisticsDto;
import com.aibaixun.system.domain.vo.QueryWordOrderVo;
import com.aibaixun.system.domain.vo.WorkOrderStatisticsVo;
import com.aibaixun.system.mapper.LkCentralfaultOrderViewMapper;
import com.aibaixun.system.service.LkCentralfaultOrderViewService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <b>LkCentralfaultOrderViewServiceImpl</b>
 *
 * @description: LkCentralfaultOrderViewServiceImpl <br>
 * @date: 2024/5/16 14:20 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Service
public class LkCentralfaultOrderViewServiceImpl extends ServiceImpl<LkCentralfaultOrderViewMapper, LkCentralfaultOrderView> implements LkCentralfaultOrderViewService {
    private static final Logger logger = LoggerFactory.getLogger(LkCentralfaultOrderViewServiceImpl.class);

    @Override
    public R<WorkOrderStatisticsVo> getWorkOrder(IndexStatisticsDto dto) {
        WorkOrderStatisticsVo dataVo = new WorkOrderStatisticsVo();
        List<LkCentralfaultOrderView> lkCentralfaultOrderViewList = baseMapper.queryLkCentralfaultOrderViewAll();
        //根据工单状态进行分组
        if (CollectionUtil.isNotEmpty(lkCentralfaultOrderViewList)){
            dataVo.setTotoal(lkCentralfaultOrderViewList.size());
            //归档
            List<LkCentralfaultOrderView> list1 = lkCentralfaultOrderViewList.stream().filter(item -> "1".equals(item.getSheetState())).collect(Collectors.toList());
            if (CollectionUtil.isNotEmpty(list1)){
                dataVo.setState2(list1.size());
            }

            List<LkCentralfaultOrderView> list2 = lkCentralfaultOrderViewList.stream().filter(item -> "2".equals(item.getSheetState())).collect(Collectors.toList());
            if (CollectionUtil.isNotEmpty(list2)){
                dataVo.setState3(list2.size());
            }

            List<LkCentralfaultOrderView> list3 = lkCentralfaultOrderViewList.stream().filter(item -> "0".equals(item.getSheetState())).collect(Collectors.toList());
            if (CollectionUtil.isNotEmpty(list3)){
                dataVo.setState1(list3.size());
            }

            List<LkCentralfaultOrderView> list4 = lkCentralfaultOrderViewList.stream().filter(item -> "10".equals(item.getSheetState())).collect(Collectors.toList());
            if (CollectionUtil.isNotEmpty(list4)){
                dataVo.setState4(list4.size());
            }


        }
        return R.ok(dataVo);
    }

    @Override
    public List<QueryWordOrderVo> queryWorkOrderList() {
        List<QueryWordOrderVo> list = baseMapper.queryWorkOrderList();
        return list;
    }
}
